package com.example.hbase;

import java.io.IOException;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.TableMapper;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;

public class StudentMapper extends TableMapper<Text, IntWritable> {

    @Override
    public void map(ImmutableBytesWritable row, Result res, Context ctx) throws InterruptedException, IOException {
        for (Cell cell : res.rawCells()) {
            byte[] byteHeight = CellUtil.cloneValue(cell);
            byte[] byteColumn = CellUtil.cloneQualifier(cell);
            if ("height".equalsIgnoreCase(Bytes.toString(byteColumn))) {
                Text writableKey = new Text("Average height");
                IntWritable writableHeight = new IntWritable(Integer.parseInt(Bytes.toString (byteHeight)) );
                ctx.write(writableKey, writableHeight);
                break;
            }
        }
    }
}

                